package com.summer.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * 作者:夏天
 * qq:1205232048
 */
public class CharacterEncodingFilter implements Filter {

    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("CharacterEncodingFilter初始化");
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");

        System.out.println("CharacterEncodingFilter执行前");
        chain.doFilter(req,resp);
        System.out.println("CharacterEncodingFilter执行后");
    }

    public void destroy() {
        System.out.println("CharacterEncodingFilter销毁");
    }
}
